<Query Kind="Program">
  <Namespace>System.Security.Cryptography</Namespace>
  <Namespace>System.Security.Cryptography.X509Certificates</Namespace>
  <RuntimeVersion>9.0</RuntimeVersion>
</Query>

class Program
{
    static void Main()
    {
		// .NET 9 引入了 X509CertificateLoader 类，它旨在解决证书加载中的一些问题。
		// 传统方式的问题包括：
		// 1. 并不是所有文件格式都能在每个操作系统上运行。
		// 2. 是一种协议偏差。
		// 3. 可能成为安全问题的来源。

		// 示例：从字节数组加载单个 X.509 证书
		// 我们将使用 .NET 9 提供的新方法 LoadCertificate 来加载证书
		byte[] certificateData = new byte[]
		{
			48,130,2,154,48,130,2,3,160,3,2,1,2,2,8,111,38,107,231,248,202,31,164,48,13,6,9,42,134,72,134,247,13,1,1,5,5,0,48,71,49,11,48,9,6,3,85,4,6,
			19,2,67,78,49,41,48,39,6,3,85,4,10,19,32,83,105,110,111,114,97,105,108,32,67,101,114,116,105,102,105,99,97,116,105,111,110,32,65,117,116,104,111,114,105,116,121,49,13,48,
			11,6,3,85,4,3,19,4,83,82,67,65,48,30,23,13,48,57,48,53,50,53,48,54,53,54,48,48,90,23,13,50,57,48,53,50,48,48,54,53,54,48,48,90,48,71,49,11,48,9,
			6,3,85,4,6,19,2,67,78,49,41,48,39,6,3,85,4,10,19,32,83,105,110,111,114,97,105,108,32,67,101,114,116,105,102,105,99,97,116,105,111,110,32,65,117,116,104,111,114,105,
			116,121,49,13,48,11,6,3,85,4,3,19,4,83,82,67,65,48,129,159,48,13,6,9,42,134,72,134,247,13,1,1,1,5,0,3,129,141,0,48,129,137,2,129,129,0,204,165,179,94,
			111,126,41,208,107,203,145,158,173,239,111,206,57,182,184,153,125,138,253,230,81,88,87,231,186,79,30,230,50,131,31,239,65,128,38,246,245,180,168,182,163,234,77,188,87,88,252,72,59,63,
			4,143,37,14,221,183,209,230,148,60,162,243,83,58,89,44,218,180,185,5,211,33,162,46,44,82,48,138,139,145,11,138,171,114,195,15,215,129,142,98,22,171,250,15,131,240,245,11,206,81,
			199,81,85,38,207,90,141,67,192,201,135,239,146,45,234,153,63,172,4,72,20,113,35,91,2,3,1,0,1,163,129,142,48,129,139,48,31,6,3,85,29,35,4,24,48,22,128,20,121,94,
			182,119,183,226,82,131,67,237,199,81,136,76,99,133,44,0,67,88,48,12,6,3,85,29,19,4,5,48,3,1,1,255,48,46,6,3,85,29,31,4,39,48,37,48,35,160,33,160,31,134,
			29,104,116,116,112,58,47,47,49,57,50,46,49,54,56,46,57,46,49,52,57,47,99,114,108,49,46,99,114,108,48,11,6,3,85,29,15,4,4,3,2,1,254,48,29,6,3,85,29,14,
			4,22,4,20,121,94,182,119,183,226,82,131,67,237,199,81,136,76,99,133,44,0,67,88,48,13,6,9,42,134,72,134,247,13,1,1,5,5,0,3,129,129,0,198,172,9,182,83,250,31,
			212,182,206,156,109,155,158,116,45,129,197,90,5,120,149,36,95,11,40,246,149,219,117,208,247,161,212,243,23,224,73,147,9,75,165,52,209,97,192,35,188,233,210,173,180,241,20,148,126,223,
			112,14,175,94,123,255,255,84,232,115,71,164,222,110,15,80,127,35,210,162,25,1,174,21,208,122,123,208,162,14,121,229,47,130,221,226,64,1,87,141,9,55,140,75,115,127,51,152,115,5,
			18,64,161,247,231,222,170,24,116,3,181,67,198,211,130,227,162,251,111,56,244
		};

		try
		{
            // 加载证书，支持 PEM 或 DER 格式
            X509Certificate2 certificate = X509CertificateLoader.LoadCertificate(certificateData);
            Console.WriteLine("证书成功加载: " + certificate.Subject);
        }
        catch (Exception ex)
        {
            Console.WriteLine("加载证书时出错: " + ex.Message);
        }
	}
}